package com.xujiang.myblog.model;

import android.content.Context;

import com.xujiang.myblog.util.AppUtils;
import com.xujiang.myblog.util.MD5Utils;

/**
 * Created by xujiang on 2017/4/18.
 *
 * 登陆和注册的模型，登陆和注册都使用这个模型进行上传数据
 * ，如果后期需要加入上传数据，请加载在这个里面
 *
 *
 */

public class Login {
    private String userId;
    private String password;
    private String OS;   //OS经过json化时会被改成小写，经过测试是因为框架的原因，请告知后台接受数据时用小写的‘os’接受数据
    private String appVersion;
    private String appVersionCode;
    private String devToken;

    public Login() {
    }

    public Login(String userId, String password, String OS, String appVersion, String appVersionCode,
                 String devToken) {
        this.userId = userId;
        this.password = password;
        this.OS = OS;
        this.appVersion = appVersion;
        this.appVersionCode = appVersionCode;
        this.devToken = devToken;
    }

    public Login(Context context, String userId, String password, String devToken) {
        this.userId = userId;
        this.password = password;
        this.devToken = devToken;
        this.OS = "android";
        try {
            this.appVersion = AppUtils.getVersionInfo(context).versionName;
            this.appVersionCode = String.valueOf(AppUtils.getVersionInfo(context).versionCode);
        } catch (Exception e) {
            this.appVersion = "1.0";
            this.appVersionCode = "1";
        }
    }

    public void md5Password() {
        this.password = MD5Utils.md5ToString(this.password);
    }

    public String getUserId() {
        return userId;
    }

    public Login setUserId(String userId) {
        this.userId = userId;
        return this;
    }

    public String getPassword() {
        return password;
    }

    public Login setPassword(String password) {
        this.password = password;
        return this;
    }

    public String getOS() {
        return OS;
    }

    public Login setOS(String OS) {
        this.OS = OS;
        return this;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public Login setAppVersion(String appVersion) {
        this.appVersion = appVersion;
        return this;
    }

    public String getAppVersionCode() {
        return appVersionCode;
    }

    public Login setAppVersionCode(String appVersionCode) {
        this.appVersionCode = appVersionCode;
        return this;
    }

    public String getDevToken() {
        return devToken;
    }

    public Login setDevToken(String devToken) {
        this.devToken = devToken;
        return this;
    }

    @Override
    public String toString() {
        return "Login{" +
                "userId='" + userId + '\'' +
                ", password='" + password + '\'' +
                ", OS='" + OS + '\'' +
                ", appVersion='" + appVersion + '\'' +
                ", appVersionCode='" + appVersionCode + '\'' +
                ", devToken='" + devToken + '\'' +
                '}';
    }
}
